﻿using ApplicationManager.Model;
using ApplicationManager.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace ApplicationManager
{
    
    public class MitmProxyManagerController : Controller
    {
        private readonly MitmProxyAppService appService;

        public MitmProxyManagerController(MitmProxyAppService appService)
        {
            this.appService = appService;
        }
        [HttpGet]
        public async Task<IActionResult> Index()
        {
            var models = await appService.GetAppStatus();
            return View(models);
        }
        /// <summary>
        /// 创建app应用
        /// </summary>
        /// <param name="appInfo"></param>
        /// <returns></returns>

        [HttpPost]
        public async Task<bool> Create(MitmProxyAppInfoRequest appInfo)
        {
            return await appService.Create(appInfo);
        }
        /// <summary>
        /// 启动已经有的应用
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<bool> Start(string id)
        {
            return await appService.Start(id);
        }

        [HttpGet]
        public async Task<bool> Stop(string id)
        {
            return await appService.Stop(id);
        }

        [HttpGet]
        public async Task<bool> Delete(string id)
        {
            return await appService.Delete(id);
        }

    }
}
